<?php

class Avpt_Publicidade_Entrada extends WP_Widget {
	function __construct() {
		parent::__construct( 'Avpt_Publicidade_Entrada', 'Avpt Publicidade Entrada', array( 'description' => 'Carrossel de publicidade' ) );
	}
	
	function widget ( $args, $instance ) {
		extract($args, EXTR_SKIP);
		$ad_cod_1 = empty ($instance['ad_cod_1']) ? '' : apply_filters('ad_cod_1', $instance['ad_cod_1']);
		$ad_cod_2 = empty ($instance['ad_cod_2']) ? '' : apply_filters('ad_cod_2', $instance['ad_cod_2']);
		$ad_cod_3 = empty ($instance['ad_cod_3']) ? '' : apply_filters('ad_cod_3', $instance['ad_cod_3']);
		$ad_cod_4 = empty ($instance['ad_cod_4']) ? '' : apply_filters('ad_cod_4', $instance['ad_cod_4']);
		$ad_cod_5 = empty ($instance['ad_cod_5']) ? '' : apply_filters('ad_cod_5', $instance['ad_cod_5']);
		$ad_cod_6 = empty ($instance['ad_cod_6']) ? '' : apply_filters('ad_cod_6', $instance['ad_cod_6']);
		$ad_cod_7 = empty ($instance['ad_cod_7']) ? '' : apply_filters('ad_cod_7', $instance['ad_cod_7']);
		$ad_cod_8 = empty ($instance['ad_cod_8']) ? '' : apply_filters('ad_cod_8', $instance['ad_cod_8']);
		$ad_cod_9 = empty ($instance['ad_cod_9']) ? '' : apply_filters('ad_cod_9', $instance['ad_cod_9']);
		$ad_cod_10 = empty ($instance['ad_cod_10']) ? '' : apply_filters('ad_cod_10', $instance['ad_cod_10']);
		$ads_to_show = array( $ad_cod_1, $ad_cod_2, $ad_cod_3, $ad_cod_4, $ad_cod_5, $ad_cod_6, $ad_cod_7, $ad_cod_8, $ad_cod_9, $ad_cod_10,);
		shuffle( $ads_to_show );
		?>		
		<div id="pub-carrossel-1" style="margin-left:40px;">
			<script type="text/javascript">
			$(document).ready(function(){
			  $('.slider1').bxSlider({
			    slideWidth: 176,
			    minSlides: 5,
			    maxSlides: 5,
			    slideMargin: 5,
			    auto: true,
			    pause: 7500,
			    controls: true,
				pager: false
			  });
			});
			</script>
			<div style="float:left;width:15px;height=100px;"></div>
			<div class="clr"></div>
			<span class="pub-retranca" style="margin-left:0;">PUBLICIDADE</span>
			<div class="vertical_space_2"></div>
			<div class="slider1">
				<?php 
				foreach ($ads_to_show as $key => $value) { ?>
					<div class="slide1"><?php echo $value; ?></div>
				<?php
				}
				?>
			</div>
		</div>
	<?php	
	}
	
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['ad_cod_1'] = $new_instance['ad_cod_1'];
		$instance['ad_cod_2'] = $new_instance['ad_cod_2'];
		$instance['ad_cod_3'] = $new_instance['ad_cod_3'];
		$instance['ad_cod_4'] = $new_instance['ad_cod_4'];
		$instance['ad_cod_5'] = $new_instance['ad_cod_5'];
		$instance['ad_cod_6'] = $new_instance['ad_cod_6'];
		$instance['ad_cod_7'] = $new_instance['ad_cod_7'];
		$instance['ad_cod_8'] = $new_instance['ad_cod_8'];
		$instance['ad_cod_9'] = $new_instance['ad_cod_9'];
		$instance['ad_cod_10'] = $new_instance['ad_cod_10'];
		return $instance;
	}	
	
	function form ( $instance ) {
		require get_template_directory() . '/widget/widget-style.php';
		$instance = wp_parse_args((array) $instance, array( 'ad_cod_1' => '', 'ad_cod_2' => '', 
			'ad_cod_3' => '', 'ad_cod_4' => '', 'ad_cod_5' => '', 'ad_cod_6' => '',
			'ad_cod_7' => '', 'ad_cod_8' => '', 'ad_cod_9' => '', 'ad_cod_10' => '' ));
		$ad_cod_1 = $instance['ad_cod_1'];
		$ad_cod_2 = $instance['ad_cod_2'];
		$ad_cod_3 = $instance['ad_cod_3'];
		$ad_cod_4 = $instance['ad_cod_4'];
		$ad_cod_5 = $instance['ad_cod_5'];
		$ad_cod_6 = $instance['ad_cod_6'];
		$ad_cod_7 = $instance['ad_cod_7'];
		$ad_cod_8 = $instance['ad_cod_8'];
		$ad_cod_9 = $instance['ad_cod_9'];
		$ad_cod_10 = $instance['ad_cod_10'];
		?>
		<p><label>Favor inserir os códigos da publicidade a partir do gestor de publicidade</label></p>		
		<p>
		  <label for="<?php echo $this->get_field_id('ad_cod_1');?>"><?php _e( 'código 1: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_1'); ?>" name="<?php echo $this->get_field_name('ad_cod_1'); ?>" value="<?php echo esc_attr($ad_cod_1); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_2');?>"><?php _e( 'código 2: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_2'); ?>" name="<?php echo $this->get_field_name('ad_cod_2'); ?>" value="<?php echo esc_attr($ad_cod_2); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_3');?>"><?php _e( 'código 3: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_3'); ?>" name="<?php echo $this->get_field_name('ad_cod_3'); ?>" value="<?php echo esc_attr($ad_cod_3); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_4');?>"><?php _e( 'código 4: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_4'); ?>" name="<?php echo $this->get_field_name('ad_cod_4'); ?>" value="<?php echo esc_attr($ad_cod_4); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_5');?>"><?php _e( 'código 5: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_5'); ?>" name="<?php echo $this->get_field_name('ad_cod_5'); ?>" value="<?php echo esc_attr($ad_cod_5); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_6');?>"><?php _e( 'código 6: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_6'); ?>" name="<?php echo $this->get_field_name('ad_cod_6'); ?>" value="<?php echo esc_attr($ad_cod_6); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_7');?>"><?php _e( 'código 7: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_7'); ?>" name="<?php echo $this->get_field_name('ad_cod_7'); ?>" value="<?php echo esc_attr($ad_cod_7); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_8');?>"><?php _e( 'código 8: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_8'); ?>" name="<?php echo $this->get_field_name('ad_cod_8'); ?>" value="<?php echo esc_attr($ad_cod_8); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_9');?>"><?php _e( 'código 9: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_9'); ?>" name="<?php echo $this->get_field_name('ad_cod_9'); ?>" value="<?php echo esc_attr($ad_cod_9); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_10');?>"><?php _e( 'código 10: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_10'); ?>" name="<?php echo $this->get_field_name('ad_cod_10'); ?>" value="<?php echo esc_attr($ad_cod_10); ?>">		  
		</p>
	<?php
	}

}



class Avpt_Publicidade extends WP_Widget {
	function __construct() {
		parent::__construct( 'Avpt_Publicidade', 'Avpt Publicidade', array( 'description' => 'Adiciona uma publicidade' ) );
	}
	
	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Publicidade' : apply_filters('widget_title', $instance['title']);
		$ad_code = empty ($instance['ad_code']) ? '' : apply_filters('ad_code', $instance['ad_code']);		
		$img_url = empty ($instance['img_url']) ? '' : apply_filters('img_url', $instance['img_url']);
		$link_url = empty ($instance['link_url']) ? '' : apply_filters('link_url', $instance['link_url']);    
		$up = empty ($instance['up']) ? '0' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '0' : apply_filters('down', $instance['down']);?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<div>
			<span class="pub-retranca">PUBLICIDADE</span>
			<?php 
			if ( $ad_code == ''  ) { ?>
				<div><a href="<?php echo $link_url ?>"><img src="<?php echo $img_url ?>" /></a></div>
			<?php	
			} else { ?>
				<div><?php echo $ad_code; ?></div> 
			<?php
			}
			?>
		</div>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);		
		$instance['ad_code'] = $new_instance['ad_code'];
		$instance['img_url'] = $new_instance['img_url'];
		$instance['link_url'] = $new_instance['link_url'];
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'ad_code' => '', 'img_url' => '', 'link_url' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$ad_code = $instance['ad_code'];
		$img_url = $instance['img_url'];
		$link_url = $instance['link_url'];
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		  <span class="nota-input-box">Opcional</span>
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('ad_code');?>"><?php _e( 'Código da publicidade: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_code'); ?>" name="<?php echo $this->get_field_name('ad_code'); ?>" value="<?php echo esc_attr($ad_code); ?>">
		</p>
		<p>Ou</p>
		<p>
		  <label for="<?php echo $this->get_field_id('img_url');?>"><?php _e( 'Imagem url: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_url'); ?>" name="<?php echo $this->get_field_name('img_url'); ?>" value="<?php echo esc_attr($img_url); ?>">			
		  <label for="<?php echo $this->get_field_id('link_url');?>"><?php _e( 'Link url: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('link_url'); ?>" name="<?php echo $this->get_field_name('link_url'); ?>" value="<?php echo esc_attr($link_url); ?>">		
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">		
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px:', 'tga') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}

}



class Avpt_Publicidade_4x145x145 extends WP_Widget {
	function __construct() {
		parent::__construct( 'Avpt_Publicidade_4x145x145', 'Avpt Publicidade 4x145x145', array( 'description' => 'Adiciona uma publicidade de tamanho 4x145x145' ) );
	}
	
	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? 'Publicidade' : apply_filters('widget_title', $instance['title']);
		$ad_cod_1 = empty ($instance['ad_cod_1']) ? '' : apply_filters('ad_cod_1', $instance['ad_cod_1']);
		$ad_cod_2 = empty ($instance['ad_cod_2']) ? '' : apply_filters('ad_cod_2', $instance['ad_cod_2']);
		$ad_cod_3 = empty ($instance['ad_cod_3']) ? '' : apply_filters('ad_cod_3', $instance['ad_cod_3']);
		$ad_cod_4 = empty ($instance['ad_cod_4']) ? '' : apply_filters('ad_cod_4', $instance['ad_cod_4']);
		$up = empty ($instance['up']) ? '0' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '0' : apply_filters('down', $instance['down']);
		?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<div id="pub-4x145x145">
			<span class="pub-retranca">PUBLICIDADE</span>
			<div class="pub-4x145x145">
				<div class="pub-145x145" style="margin: auto 5px 5px auto; float: left; background-color: #efefef;"><?php echo $ad_cod_1?></div>
				<div class="pub-145x145" style="margin: auto auto 5px 5px; float: right; background-color: #efefef;"><?php echo $ad_cod_2?></div>	
				<div class="pub-145x145" style="margin: 5px 5px 5px auto; float: left; background-color: #efefef;"><?php echo $ad_cod_3?></div>
				<div class="pub-145x145" style="margin: 5px auto auto 5px; float: right; background-color: #efefef;"><?php echo $ad_cod_4?></div>		
			</div>
		</div>
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['ad_cod_1'] = $new_instance['ad_cod_1'];
		$instance['ad_cod_2'] = $new_instance['ad_cod_2'];
		$instance['ad_cod_3'] = $new_instance['ad_cod_3'];
		$instance['ad_cod_4'] = $new_instance['ad_cod_4'];
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'ad_cod_1' => '', 
			'ad_cod_2' => '', 'ad_cod_3' => '', 'ad_cod_4' => '', 'up' => '', 'down' => '' ));
		$title = strip_tags($instance['title']);
		$ad_cod_1 = $instance['ad_cod_1'];
		$ad_cod_2 = $instance['ad_cod_2'];
		$ad_cod_3 = $instance['ad_cod_3'];
		$ad_cod_4 = $instance['ad_cod_4'];		
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e( 'Título: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		  <span class="nota-input-box">Opcional</span>
		</p>		
		<p>
		  <label for="<?php echo $this->get_field_id('ad_cod_1');?>"><?php _e( 'código 1: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_1'); ?>" name="<?php echo $this->get_field_name('ad_cod_1'); ?>" value="<?php echo esc_attr($ad_cod_1); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_2');?>"><?php _e( 'código 2: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_2'); ?>" name="<?php echo $this->get_field_name('ad_cod_2'); ?>" value="<?php echo esc_attr($ad_cod_2); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_3');?>"><?php _e( 'código 3: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_3'); ?>" name="<?php echo $this->get_field_name('ad_cod_3'); ?>" value="<?php echo esc_attr($ad_cod_3); ?>">
		  <label for="<?php echo $this->get_field_id('ad_cod_4');?>"><?php _e( 'código 4: ' ); ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('ad_cod_4'); ?>" name="<?php echo $this->get_field_name('ad_cod_4'); ?>" value="<?php echo esc_attr($ad_cod_4); ?>">		  
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e( 'Espaço acima em px: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">		
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e( 'Espaço abaixo em px:' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}

}









